<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>代码生成管理</title>

    <!-- Bootstrap -->
    <link href="./bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<div class="container-fluid">


    <div style="width: 600px; margin: 0 auto;">
        <h1>你好，世界！</h1>
        <hr />
        <button id="startBtn" type="button" class="btn btn-danger" onclick="start(this)"> 启动服务 </button>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" class="btn btn-default" value="打开项目管理" onclick="openTab()"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" class="btn btn-default" value="系统配置" onclick="openSetting()"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" class="btn btn-info" value="浏览器打开【项目管理】" onclick="openInBrowser()"/>
        <br/>
        <div id="showMsg"></div>

    </div>

    <!-- 提示框 -->
    <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                未配置，请先配置服务。
            </div>
        </div>
    </div>

</div>
<script type="text/javascript">

    var DispatcherHandle = 'test';
    function start() {
        var obj = {type: "start", params: {name: "08888"}};
        var res = DispatcherHandle.dispatcher(JSON.stringify(obj));
        var retObj = JSON.parse(res);
        var code = retObj.code;

        // 检测服务启动情况: 2001 启动中；3001 启动失败；2002 运行中；3002 未配置文件
        if(code == 2001) {
            $('#startBtn').html('启动中...');
            $('#showMsg').html('');

            // 检查并更新状态
            setTimeout(function(){
                start();
            }, 1000);
        } else if(code == 2002) {
            $('#startBtn').html('运行中...');
            $('#showMsg').html('');
            $('#startBtn').removeClass('btn-danger');
            $('#startBtn').addClass('btn-success');
        } else if(code == 3001) {
            $('#showMsg').html('<p class="bg-warning">启动失败！请查看日志。</p>');
            // open 日志文件
        } else if(code == 3002) {
            $('#showMsg').html('<p class="bg-warning">系统配置未设置，请先设置。</p>');
            setTimeout(function () {
                openSetting();
            }, 1200);
        }
    }

    // 在浏览器中打开服务管理页面
    function openInBrowser() {
        var obj = {type: "openInBrowser", params: {}};
        DispatcherHandle.dispatcher(JSON.stringify(obj));
    }

    function openTab() {
        var obj = {type: "openTab", params: {url: "http://localhost:9090/code_main/index.html"}};
        DispatcherHandle.dispatcher(JSON.stringify(obj));
    }

    function openSetting() {
        var obj = {type: "openSetting", params: {}};
        DispatcherHandle.dispatcher(JSON.stringify(obj));
    }

    // 获取服务运行状态
    setTimeout(function(){
        start();
    }, 1000);

</script>

<script src="./jquery/jquery.min.js"></script>
<script src="./bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</body>
</html>